
extern "C" {
#include <jni.h>
#include "libavcodec/avcodec.h"
#include "EncoderMediaCodec.h"
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_jsx_nativelibs_ffmpeg_Ffmpeg60_getAllEncoders(JNIEnv *env, jobject thiz) {
    // 定义临时缓存区
    char info[20000] = {0};
    // 初始化编码器遍历器
    void *opaque = NULL;
    const AVCodec *avcodec = av_codec_iterate(&opaque);

    // 遍历所有支持的编码器
    while (avcodec != NULL) {
        sprintf(info, "%s--->%s\n", info, avcodec->name);
        avcodec = av_codec_iterate(&opaque);
    }
    return env->NewStringUTF(info);
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_jsx_nativelibs_ffmpeg_Ffmpeg60_getVersion(JNIEnv *env, jobject thiz) {
    char info[200] = {0};
    // 初始化编码器遍历器
    sprintf(info, "%s%s,", "Version:", av_version_info());
    return env->NewStringUTF(info);
}

extern "C"
JNIEXPORT jlong JNICALL
Java_com_jsx_nativelibs_ffmpeg_Ffmpeg60_init(JNIEnv *env, jobject thiz, jint width, jint height,
                                             jint bit_rate, jbyte fps, jint group_size) {
    EncoderMediaCodec *mediaCodec = new EncoderMediaCodec();
//    int init = mediaCodec->init(width, height, bit_rate, fps, group_size);
    int init = mediaCodec->init2();
    if (init == 0) {
        return reinterpret_cast<jlong>(mediaCodec);
    } else {
        return init;
    }
}

extern "C"
JNIEXPORT void JNICALL
Java_com_jsx_nativelibs_ffmpeg_Ffmpeg60_destroy(JNIEnv *env, jobject thiz, jlong context) {
    // TODO: implement destroy()
}
extern "C"
JNIEXPORT void JNICALL
Java_com_jsx_nativelibs_ffmpeg_Ffmpeg60_encoderOneFrameByARGB(JNIEnv *env, jobject thiz,
                                                              jlong context, jbyteArray in_buff,
                                                              jbyteArray out_buff) {
    // TODO: implement encoderOneFrameByARGB()
}

